package com.test.mchelepesa.bean_rice;

import java.util.TimeZone;
import java.util.TreeMap;

import android.text.TextUtils;

import com.test.mchelepesa.bean_rice.config_info_rice.GlobalConfig_rice;
import com.test.mchelepesa.constant_rice.Constant_rice;
import com.test.mchelepesa.constant_rice.Url_rice;
import com.test.mchelepesa.util_rice.analytics_rice.timezone_rice.TimeZoneHostEnum_rice;

public class StaticConfig_rice {

    public static String Upload_Info_Url = "";

    public static String Country_Word = "";

    public static String Select_Country = "";

    public static GlobalConfig_rice.CountryConfig Country_Config;

    private static String TzID = "";

    public final static TreeMap<String,String> Country_Suffix_Map = new TreeMap<String,String>(){{
        put(Constant_rice.Country_Cote, Constant_rice.Suffix_Cote);
        put(Constant_rice.Country_Ghana, Constant_rice.Suffix_Ghana);
        put(Constant_rice.Country_Nigeria, Constant_rice.Suffix_Nigeria);
        put(Constant_rice.Country_Uganda, Constant_rice.Suffix_Uganda);
        put(Constant_rice.Country_Kenya, Constant_rice.Suffix_Kenya);
        put(Constant_rice.Country_Tanzania, Constant_rice.Suffix_Tanzania);
        put(Constant_rice.Country_Senegal, Constant_rice.Suffix_Senegal);
    }};

    public final static TreeMap<String,String> Country_Money_Unit_Map = new TreeMap<String,String>(){{
        put(Constant_rice.Country_Cote, Constant_rice.Money_Unit_Cote);
        put(Constant_rice.Country_Ghana, Constant_rice.Money_Unit_Ghana);
        put(Constant_rice.Country_Nigeria, Constant_rice.Money_Unit_Nigeria);
        put(Constant_rice.Country_Uganda, Constant_rice.Money_Unit_Uganda);
        put(Constant_rice.Country_Kenya, Constant_rice.Money_Unit_Kenya);
        put(Constant_rice.Country_Tanzania, Constant_rice.Money_Unit_Tanzania);
        put(Constant_rice.Country_Senegal, Constant_rice.Money_Unit_Senegal);
    }};

    public final static TreeMap<String,String> Country_Mobile_Prefix_Map = new TreeMap<String,String>(){{
        put(Constant_rice.Country_Cote, Constant_rice.Mobile_Prefix_Cote);
        put(Constant_rice.Country_Ghana, Constant_rice.Mobile_Prefix_Ghana);
        put(Constant_rice.Country_Nigeria, Constant_rice.Mobile_Prefix_Nigeria);
        put(Constant_rice.Country_Uganda, Constant_rice.Mobile_Prefix_Uganda);
        put(Constant_rice.Country_Kenya, Constant_rice.Mobile_Prefix_Kenya);
        put(Constant_rice.Country_Tanzania, Constant_rice.Mobile_Prefix_Tanzania);
        put(Constant_rice.Country_Senegal, Constant_rice.Mobile_Prefix_Senegal);
    }};

    public static String getMobilePrefix(){
        if (TextUtils.isEmpty(Select_Country)) return "";
        return Country_Mobile_Prefix_Map.get(Select_Country);
    }

    public static String getMoneyUnit(String currency){
        if (!TextUtils.isEmpty(currency)) return currency;
        if (TextUtils.isEmpty(Select_Country)) return "";
        return Country_Money_Unit_Map.get(Select_Country);
    }

    public static String getCountrySuffix(){
        if (TextUtils.isEmpty(Select_Country)) return "";
        return Country_Suffix_Map.get(Select_Country);
    }

    public static String getCountryUrlPrefix(){

        if (isTanz())
            return "/ricecashtanzv2";
        else if (isSen())
            return "/ricecashsenegal";
        else return "/ricecashfcfa";
    }

    public static boolean isSpecialBindAccount(){
        return Select_Country.equalsIgnoreCase(Constant_rice.Country_Cote) || Select_Country.equalsIgnoreCase(Constant_rice.Country_Senegal);
    }

    public static String getBaseUrl(){
        return Url_rice.Url;
    }

    public static boolean gtSmsKeyWord_Mobile(String address){

        String[] filter = null;

        if (isTanz())
            filter = Constant_rice.SmsKeyWord_Mobile_Tanzania;
        else if (isSen())
            filter = Constant_rice.SmsKeyWord_Mobile_Senegal;
        else filter = Constant_rice.SmsKeyWord_Mobile_Cote;

        return containIgnoreCase(address,filter);

    }

    public static boolean gtSmsKeyWord_Content(String body){

        String[] filter = null;

        if (isTanz())
            filter = Constant_rice.SmsKeyWord_Content_Tanzania;
        else if (isSen())
            filter = Constant_rice.SmsKeyWord_Content_Senegal;
        else filter = Constant_rice.SmsKeyWord_Content_Cote;

        return containIgnoreCase(body,filter);

    }

    public static String gtTzId(){
        if (TextUtils.isEmpty(TzID)) TzID = TimeZone.getDefault().getID().toLowerCase();
        return TzID;
    }

    public static boolean isTanz(){
        if (TextUtils.isEmpty(TzID)) TzID = TimeZone.getDefault().getID().toLowerCase();
        return TzID.contains(TimeZoneHostEnum_rice.TimeZoneTanzania.getTimeZoneId().toLowerCase());
    }

    public static boolean isSen(){
        if (TextUtils.isEmpty(TzID)) TzID = TimeZone.getDefault().getID().toLowerCase();
        return TzID.contains(TimeZoneHostEnum_rice.TimeZoneSenegal.getTimeZoneId().toLowerCase());
    }

    public static boolean isCote(){
        if (TextUtils.isEmpty(TzID)) TzID = TimeZone.getDefault().getID().toLowerCase();
        return TzID.contains(TimeZoneHostEnum_rice.TimeZoneFcfa.getTimeZoneId().toLowerCase());
    }

    private static boolean containIgnoreCase(String src,String[] filterArr){
        if (TextUtils.isEmpty(src)) return false;
        String srcLowerCase = src.toLowerCase();
        for (String filter:filterArr){
            if (!TextUtils.isEmpty(filter) && srcLowerCase.contains(filter.toLowerCase()))
                return true;
        }
        return false;
    }

}
